package com.ylfstu.homework;

public class Homework02_2 {
    public static void main(String[] args) {
        String name = "jiau";
        String psd = "123212";
        String email = "eqw@";

        try {
            userRegister(name, psd, email);
            System.out.println("注册成功！");
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }

    public static void userRegister(String name, String psd, String email) {

        if (!(name.length() >= 2 && name.length() <= 4)) {
            throw new RuntimeException("用户名为2~4");
        }

        if (!(psd.length() == 6 && isDigital(psd))) {
            throw new RuntimeException("密码长度为6，必须全为数字");
        }

        int i = email.indexOf("@");
        int j = email.indexOf(".");
        if (!(i > 0 && i < j)) {
            throw new RuntimeException("必须有@和. 且@在.前面");
        }
    }

    public static boolean isDigital(String psd) {
        char[] chars = psd.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            if (chars[i] < '0' && chars[i] > '9') {
                return false;
            }
        }
        return true;
    }
}
